<script>
	import * as api from '@/request/app.js'; // 引入api 方法
	import local from '@/utils/localStorage.js'; //引入本地存储方法
		import update from '@/utils/update.js'; //app 升级
	export default {
		globalData: {
			s: '',
			n: '',
			h: '',
			width: '',
			system: ''
		},
		onLaunch: function() {
			this.publicConfig()
			// #ifdef MP-WEIXIN
			update.wxUpdate();
			// #endif
			uni.$off('updateuserinfo')
			uni.$on('updateuserinfo', () => {
				this.getuserinfo()
			})
			uni.$off('updatelogin')
			uni.$on('updatelogin', () => {
				console.log(111111);
				this.getLogincode()
			})
		},
		methods: {
			initWEIXIN() {
				// #ifdef MP-WEIXIN
				console.log(1);
				let system = {}
				// uni.getSystemInfo()
				uni.getSystemInfo({
					success: function(res) {
						system = res
					}
				});
				console.log(system);
				// let  = ret[1]
				let menu = uni.getMenuButtonBoundingClientRect()
				console.log(menu);
				this.globalData.s = system.statusBarHeight //状态栏高度
				this.globalData.n = (menu.top - system.statusBarHeight) * 2 + menu.height //导航栏高度
				this.globalData.h = menu.height
				this.globalData.width = menu.width
				this.globalData.system = system
				// #endif
			},
			async publicConfig() {
				const {
					code,
					data
				} = await api.publicConfig()
				if (code == 0) {
					local.set('config', data)
				}
			},
			async getLogincode() {
				const ret = await uni.login()
				console.log(ret.errMsg);
				if (ret.errMsg == 'login:ok') {
					this.login(ret.code)
				}
			},
			async login(code) {
				console.log(local.get('puserId') || 0)
				const ret = await api.login({
					code,
					puserid: local.get('puserId') || 0
				})
				if (ret.code == 0) {
					local.set('token', ret.data.token)
					this.getuserinfo()
				}
			},
			async getuserinfo() {
				const {
					code,
					data
				} = await api.getuserinfo()
				if (code == 0) {
					local.set('userinfo', data)
				}
			}
		},
		onShow: function() {
			console.log('App Show')
			this.getLogincode()
			this.initWEIXIN()
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "@/css/index.scss";
	@import '@climblee/uv-ui/index.scss';

	::v-deep .uv-count-down__text {
		color: #FF1348 !important;
		font-size: 22rpx !important;
		font-weight: 500 !important;
	}

	.buttons {
		background: #FFF0EF;
		border-radius: 12rpx;
	}

	button::after {
		border: none;
	}

	button {
		position: relative;
		display: block;
		margin: 0 auto;
		padding: 0;
		box-sizing: border-box;
		text-align: center;
		background-color: #fff;
		width: 100%;
		height: 100%;
	}

	/*每个页面公共css */
	page {
		width: 750rpx;
		/* // height: 1624rpx; */
		background: #F5F5F5;
		/* // background-color: red; */
	}

	.safe-area-inset-bottom {
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}

	.button {
		background: linear-gradient(270deg, #FE6740 0%, #FE8B1D 100%);
		border-radius: 80rpx;
	}

	.bottom {
		position: fixed;
		bottom: 0;
		width: 750rpx;
		// height: 166rpx;
		padding: 10rpx 0;
		background: #FFFFFF;
		box-shadow: 0rpx -4rpx 50rpx 0rpx rgba(0, 0, 0, 0.05);
		border-radius: 12rpx 12rpx 0 0;
	}
</style>